<?php
// Function to generate table from database results
function generate_table($db_result) {
	echo '<table class="table table-striped table-bordered table-condensed">';
   	echo '<thead>';
   	echo '<tr>';
   	echo '<th>Description</th>';
   	echo '<th>Link URL</th>';
   	echo '<th>Date</th>';
   	echo '</tr>';
   	echo '</thead>';
   	echo '<tbody>';

	while($row=mysql_fetch_assoc($db_result)) {
    	echo '<tr><td><a href="'.$row['link'].'">'.$row['description'].'</a></td>';
    	echo '<td>'.$row['link'].'</td>';
    	echo '<td>'.$row['date'].'</td></tr>';
    }

    echo '</tbody>';
    echo '</table>';
}

function generate_tech_table($db_result) {
	echo '<table class="table table-striped table-bordered table-condensed">';
   	echo '<thead>';
   	echo '<tr>';
   	echo '<th>ID</th>';
   	echo '<th>Technology</th>';
   	echo '</tr>';
   	echo '</thead>';
   	echo '<tbody>';

	while($row=mysql_fetch_assoc($db_result)) {
    	echo '<tr><td>'.$row['tech_id'].'</td>';
    	echo '<td><a href="'.$_SERVER['PHP_SELF'].'?t='.$row['tech_id'].'">'.$row['technology'].'</a></td></tr>';
    }

    echo '</tbody>';
    echo '</table>';
}

function generate_tabs($db_result) {
	echo '<div class="span3">';
	echo '<ul class="nav nav-pills nav-stacked">';
	while ($row=mysql_fetch_assoc($db_result)) {
		echo '<li><a href="#'.$row['tab_id'].'" data-toggle="tab">'.$row['title'].'</a></li>';
	}
	echo '</ul></div>';
	echo '<div class="span8"><div class="tab-content">';
	if (mysql_num_rows($db_result)>0){
		mysql_data_seek($db_result, 0);
	}
	while($row=mysql_fetch_assoc($db_result)) {
		echo '<div class="tab-pane" id="'.$row['tab_id'].'">'.$row['content'].'</div>';
	}
	echo '</div></div>';
}

// Function to generate pagination
function generate_pagi($total_links, $limit, $page) {
	$pagi=$total_links/$limit;

	echo '<div class="pagination">';
	echo '<ul>';

	for ($i=0; $i<$pagi; $i++) {
		if ($page==$i) {
			echo '<li class="active"><a href="?p='.$i.'">'.($i+1).'</a></li>';
		} else {
			echo '<li><a href="?p='.$i.'">'.($i+1).'</a></li>';
		}
	}
	echo '</ul>';
	echo '</div>';
}

?>